package flex.cc.medical.controller;

import flex.cc.common.utils.CommonUtils;
import flex.cc.core.support.BaseController;
import flex.cc.medical.service.MedicalService;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wkangle
 * @className MedicalServiceController
 * @description 医护类服务模块
 * @time 2022-02-08 09:34:20
 */
@SuppressWarnings("restriction")
@RestController
@RequestMapping(value = "/vehicleSvr/medicalService/wechat")
public class MedicalServiceController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(MedicalServiceController.class);

    @Autowired
    private MedicalService medicalService;

    @PostMapping(value = "/activating")
    @ApiOperation(httpMethod = "POST", value = "注册兑换")
    public Wrapper<Map<String, String>> activating(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("MedicalServiceController -- activating() ====> {}", reqVo);
        Map<String, String> activating = medicalService.activating(reqVo);
        return WrapMapper.ok(activating);
    }

    @PostMapping(value = "/initEncrypt")
    @ResponseBody
    @ApiOperation(httpMethod = "POST", value = "请求医护合作方参数加密")
    public Wrapper<Map<String, String>> initEncrypt(@ApiParam(name = "reqVo", value = "请求信息") @RequestBody Map<String, Object> reqVo) {
        logger.info("MedicalServiceController 请求医护合作方参数加密 ====> {}", reqVo);
        Map<String, String> initEncrypt = medicalService.initEncrypt(reqVo);
        return WrapMapper.ok(initEncrypt);
    }


    public static void main(String[] args) {
        //Map<String, Object> body = new HashMap<String, Object>();
        //body.put("activateCode", "JDSKJDLFJLDFJSJFLKSJDF");
        //body.put("phone", "18612319729");
        //body.put("effDate", "2022-01-26 00:00:00");
        //body.put("expDate", "2022-05-26 23:59:59");
        //
        //String json = CommonUtils.toJSONString(body);
        //System.out.println("原文==" + json);
        //Object parse = JSONObject.parse(json);
        //System.out.println("其他==" + parse);
        //
        //// 加密工具
        //String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCEpBfaWtT40yDV+HQTkBLQlyNua5SNKuYjXeRGwIVRFChqJHIp0UBqGPRZLcnBRNwcUMfEEWLXyzPzckEUKfD6FvMZjRbmBw5+aYTAkHZFIuMzzjnV6VVwZRKbhoOBdAH5yZsGsLE5UlbHLb8vF2MB/Mk7IL1v4IHzRqHJPjD5jwIDAQAB";
        //String rsaEncryptOAEP = OpenApiUtil.RSAEncryptOAEP(CommonUtils.toJSONString(body), OpenApiUtil.readPublicKey(publicKey));
        //System.out.println("加密==" + rsaEncryptOAEP);
        //String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAISkF9pa1PjTINX4dBOQEtCXI25rlI0q5iNd5EbAhVEUKGokcinRQGoY9FktycFE3BxQx8QRYtfLM/NyQRQp8PoW8xmNFuYHDn5phMCQdkUi4zPOOdXpVXBlEpuGg4F0AfnJmwawsTlSVsctvy8XYwH8yTsgvW/ggfNGock+MPmPAgMBAAECgYBaxLBODLqRTGm8Aznr6Tv24nasqZIOyLyUlzwP7s9MnK7LdAVr+HZMJKeSH3Nhfu3hsqYB1qP9aGE0x4shcVIl1UGXp1MuIf8Hm6XyrFVDB4YzkZWEwsIfwzrXXPbnS4fm0RF1vYtv53geCTjjN8ojybU12RBddIgM0Hd2pHYuAQJBAMks/DX+BQ8WoUMXgVu5Q5/u5gMWcGdc1vZanX8zAgji5JEaYFxPCis99/WHihMw9FCZuwCNHQn9J1xt+ctVhTECQQCoyckVGDVUIxmM0orQmDQJKGPxQzwWb39fZ+0WfDiIK07Ml/3Ug4jSqVrD6fFGD197ozgTXfOktkpEmGqNLbq/AkEAv8nqPFMKYaMSZFLxWQ+bP8rSb5kh2fixWrVytwRa6Tvd6dO6j+YubKEsVmA8KyWdlYWpuNHPIGm+76hM3yON0QJAX2pyufINc5rD/s+mmXTxNZwXo3OWrDgrkQt3A5cFfjS9PvtNCq2w0yXZoZbGRgy6tXH3aTtbWGmUYmKnGVgYkQJAHwvfm4Dlf35z410hjBenHuvPGhmI5/yt41PH89eTsgoU04rSGUBNBOeJbLVnVuZBInD4jsz6x1KhvxQ4ydu1Dw==";
        //String rsaDecryptOAEP = OpenApiUtil.RSADecryptOAEP(rsaEncryptOAEP, OpenApiUtil.readPrivateKey(privateKey));
        //System.out.println("解密==" + rsaDecryptOAEP);

        Map<String, Object> body = new HashMap<String, Object>();
        body.put("activateCode", "JDSKJDLFJLDFJSJFLKSJDF"); // 激活码
        body.put("phone", "18612319729"); // 手机号
        body.put("effDate", "2022-01-26 00:00:00"); // 生效日期
        body.put("expDate", "2022-05-26 23:59:59"); // 失效日期

        String json = CommonUtils.toJSONString(body);
        // Base64加密
        // 加密
        byte[] bytes = json.getBytes();
        String encodeToString = Base64.getEncoder().encodeToString(bytes);
        System.out.println("密文==" + encodeToString);

        // 解密
        encodeToString = "eyJhY3RpdmF0ZUNvZGUiOiJKRFNLSkRMRkpMREZKU0pGTEtTSkRGIiwicGhvbmUiOiIxODYxMjMxOTcyOSIsImVmZkRhdGUiOiIyMDIyLTAxLTI2IDAwOjAwOjAwIiwiZXhwRGF0ZSI6IjIwMjItMDUtMjYgMjM6NTk6NTkiLCJhcHBDb2RlIjoiWkhPTkdYVUFOSFVBWVUifQ==";
        String toString = new String(Base64.getDecoder().decode(encodeToString));
        System.out.println("明文==" + toString);

    }

}
